<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/script/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
	$(function() {
		$("#deleteUserById").click(function(e) {
			e.preventDefault();
			$("form").attr("action", this.href).submit();
		})
	});
</script>
<style type="text/css">
	.textAlignCenter {
		text-align: center;
	}
	a {
		text-decoration: none;
	}
	.bigFont {
		font-size: large;
	}
</style>
</head>
<body>
	<form action="" method = "POST">
		<input type = "hidden" name = "_method" value = "DELETE">	
	</form>

	<a href = "<%=request.getContextPath()%>/userService/getAllUsers"
				class="bigFont">show all users</a>
	<br /><br />
	<a class="bigFont" href = "${pageContext.request.contextPath}/pages/user/
				userInput.jsp">add a user</a>
	<br /><br />
	<table border = "1" cellpadding="0" cellspacing="0" width="600">
		<tr class="textAlignCenter">
			<th width="15%">userName</th>
			<th width="15%">password</th>
			<th width="15%">sex</th>
			<th width="25%">email</th>
			<th width="30%">operate</th>
		</tr>
		<c:forEach items="${users}" var="user">
			<tr class="textAlignCenter">
				<td>${user.userName}</td>
				<td>${user.password}</td>
				<td>${user.sex}</td>
				<td>${user.email}</td>
				<td><a href="${pageContext.request.contextPath}/userService/
							getUserById/${user.id}">编辑</a>&nbsp;|&nbsp;
					<a id = "deleteUserById" href="${pageContext.request.contextPath}/userService/
							deleteUserById/${user.id}">删除</a>
				</td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>